package com.pactera.madp.cp.service.sync.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pactera.madp.cp.api.entity.sync.MaTodayDataBoardEntity;
import com.pactera.madp.cp.api.vo.employee.SidebarMarkingDataTendencyVo;
import com.pactera.madp.cp.mapper.sync.MaTodayDataBoardMapper;
import com.pactera.madp.cp.service.sync.MaTodayDataBoardService;
import org.springframework.stereotype.Service;

/**
 * @author Deming.Chang
 * @title 经理视图 -> 当日数据看板 业务接口实现
 * @date 2022-05-20
 */
@Service
public class MaTodayDataBoardServiceImpl extends ServiceImpl<MaTodayDataBoardMapper, MaTodayDataBoardEntity> implements MaTodayDataBoardService {

    @Override
    public SidebarMarkingDataTendencyVo todayData(String wxUserId, String date) {
        SidebarMarkingDataTendencyVo vo = new SidebarMarkingDataTendencyVo();
        MaTodayDataBoardEntity todayEntity = this.getOne(
                Wrappers.<MaTodayDataBoardEntity>lambdaQuery()
                        .eq(MaTodayDataBoardEntity::getRecommendId, wxUserId), false
        );
        if (todayEntity != null) {
            vo.setTime(date);
            vo.setVisitorNumber(todayEntity.getTodayVisitors());
            vo.setBrowsesNumber(todayEntity.getTodayBrowses());
        } else {
            vo.setTime(date);
            vo.setVisitorNumber(0L);
            vo.setBrowsesNumber(0L);
        }
        return vo;
    }

    @Override
    public Long todayVisitor(String wxUserId) {
        MaTodayDataBoardEntity todayEntity = this.getOne(
                Wrappers.<MaTodayDataBoardEntity>lambdaQuery()
                        .eq(MaTodayDataBoardEntity::getRecommendId, wxUserId), false
        );
        if (todayEntity != null) {
            return todayEntity.getTodayVisitors();
        } else {
            return 0L;
        }
    }

}
